//
//  AudioManager.h
//  LineByLine
//
//  Created by 병철 김 on 11. 10. 21..
//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>

@protocol AudioManagerDelegate <NSObject>
- (void) didFinishPlaying;
- (void) didFinishRecording;
- (void) didFinishPlayRecord;
- (void) didFinishRetry:(BOOL)retry;
@end

@interface AudioManager : NSObject<AVAudioSessionDelegate, AVAudioPlayerDelegate, AVAudioRecorderDelegate> {
    id book;
    id<AudioManagerDelegate> audioDelegate;
    
    AVAudioPlayer *audioPlayer;
    AVAudioRecorder *audioRecorder;
    AVAudioPlayer *audioRecorderPlayer;
    NSMutableArray *avgPower;
    NSTimer *timer;
    
    SystemSoundID soundFileObject;
    
    float maxAverage;
    SEL afterRecordProcess;
}

+ (AudioManager*) sharedAudioManager;

- (void) setUpAudioSession;
- (BOOL) prepareBook:(id) book;
- (void) playBookStart:(float)start duration:(float)duration;
- (void) stopPlay;
- (void) closePlayer;
- (void) recordBookPage:(NSInteger) sentenceId;
- (BOOL) playRecordBookPage:(NSInteger) sentenceId;
- (void) stopRecord;
- (void) playBeep;
- (void) askRetry;
- (void) pausePlay;

@property(readonly, nonatomic) AVAudioPlayer *audioPlayer;
@property(assign, nonatomic) id<AudioManagerDelegate> audioDelegate;
@end
